﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WTwitter.ViewModel;
using WTwitter.Model.UserData;

namespace WTwitter.View {
	/// <summary>
	/// OptionDialog.xaml の相互作用ロジック
	/// </summary>
	public partial class OptionDialog : Window {
		private OptionViewModel _target;
		public OptionDialog(OptionViewModel target) {
			this.DataContext = target;
			_target = target;
			InitializeComponent();
		}

		private void Window_Loaded(object sender, RoutedEventArgs e) {
			_target.BeginEdit();
			BindingGroup.BeginEdit();
			PasswordBox.Password = _target.UserInfo.Password;
		}

		private void OkButton_Click(object sender, RoutedEventArgs e) {
			_target.CommitEdit();
			BindingGroup.CommitEdit();
			_target.UserInfo.Password = PasswordBox.Password;
			(this.DataContext as OptionViewModel).Save();
			this.DialogResult = true;
			this.Close();
		}

		private void CancelButton_Click(object sender, RoutedEventArgs e) {
			_target.CancelEdit();
			BindingGroup.CancelEdit();
			this.Close();
		}
		
	}
}
